//
//  VisitorTableViewController.swift
//  Weibo1
//
//  Created by apple on 15/12/26.
//  Copyright © 2015年 idcast. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 访客视图
    var visitorView: VisitorView?
    ///用户登陆标记
    private var userLogon = false
    
    override func loadView() {
        print("come  here")
       //如果登陆了就调用super 没登陆就替换跟试图
        
        
        userLogon ? super.loadView() : setupVisitorView()
    }
    
    ///设置访客试图
    private func setupVisitorView() {

        // 替换根视图
        visitorView = VisitorView()

        view = visitorView
        
        // 添加监听方法
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
        
    }
}


//MARK: 访客试图监听方法
extension VisitorTableViewController {

    func visitorViewDidRegister() {
        print("注册")
    }
    func visitorViewDidLogin() {

        let vc = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
